package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Organization;
import cn.wolfcode.crm.mapper.OrganizationMapper;
import cn.wolfcode.crm.query.ObjectQuery;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.service.IOrganizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class OrganizationServiceImpl implements IOrganizationService {
    @Autowired
    private OrganizationMapper organizationMapper;

    public void save(Organization record) {
        //初始化员工状态
       // employee.setState(CRMConstant.Organization.STATE_NORMAL);

        organizationMapper.insert(record);
    }

    public void delete(Long id) {
            organizationMapper.deleteByPrimaryKey(id);


    }

    public void update(Organization record) {
        organizationMapper.updateByPrimaryKey(record);
    }

    public Organization get(Long id) {
        Organization employee = organizationMapper.selectByPrimaryKey(id);
        return employee;
    }

    public List<Organization> getAll() {

        return organizationMapper.selectAll();
    }

    public PageResult<Organization> query(ObjectQuery qo) {
        int totalCount = organizationMapper.queryForCount(qo);
        if (totalCount == 0) {
            return new PageResult<Organization>(totalCount, Collections.<Organization>emptyList());
        }


        return new PageResult<Organization>(totalCount, organizationMapper.queryForList(qo));
    }

   /* public void batchDelete(Long[] ids) {
        if (ids != null) {
            organizationMapper.batchDelete(ids);
          *//*  for (Long id : ids) {
                organizationMapper.deleteOrganizationRoleRelationByOrganization(id);
            }
*//*
        }
    }*/


    public void changState(Long id) {
        organizationMapper.changState(id);
    }

    public List<Organization> selectAll() {
        return organizationMapper.selectAll();
    }

    public List<Organization> queryOrg() {
        return organizationMapper.queryOrg();
    }


}
